﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace WebService1
{
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string queryString(String taskCode, String cardCode, String birthday, String idCard, String name)
        {
            string conn = ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString;
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from PassportInfo where ");
            if (!string.IsNullOrEmpty(taskCode))
                sql.Append("taskCode='" + taskCode + "' and ");
            if (!string.IsNullOrEmpty(cardCode))
                sql.Append("cardCode='" + cardCode + "' and ");
            if (!string.IsNullOrEmpty(birthday))
                sql.Append("birthday='" + birthday + "' and ");
            if (!string.IsNullOrEmpty(idCard))
                sql.Append("idCard='" + idCard + "' and ");
            if (!string.IsNullOrEmpty(name))
                sql.Append("name='" + name + "' and ");
            string strSql = sql.ToString();
            if (strSql.LastIndexOf("and")!=-1)
                strSql=strSql.Substring(0, strSql.LastIndexOf("and"));
            else
                return "";
            SqlDataReader reader= WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(conn,strSql);
            StringBuilder ret = new StringBuilder();
            while(reader.Read())
            {
                ret.Append("姓名:");
                ret.Append(Convert.ToString(reader["name"]));
                ret.Append(",");
                ret.Append("出生日期:");
                DateTime Birthday=Convert.ToDateTime(reader["birthday"]);
                ret.Append(Birthday.ToString("yyyyMMdd"));
                ret.Append(",");
                ret.Append("身份证号:");
                ret.Append(Convert.ToString(reader["idCard"]));
                ret.Append(",");
                ret.Append("证件号码:");
                ret.Append(Convert.ToString(reader["cardCode"]));
                ret.Append(",");
                ret.Append("业务编号:");
                ret.Append(Convert.ToString(reader["业务编号"]));
                ret.Append(";");
            }
            return ret.ToString();
        }
    }
}
